<!-- @format -->

<!--
 - MineAdmin is committed to providing solutions for quickly building web applications
 - Please view the LICENSE file that was distributed with this source code,
 - For the full copyright and license information.
 - Thank you very much for using MineAdmin.
 -
 - @Author X.Mo<root@imoi.cn>
 - @Link   https://gitee.com/xmo/mineadmin-vue
-->
<template>
	<!-- <st-welcome /> -->
	<StoreCount :data="totlaCount" />
	<operational-count :data="totlaCount" />
	<st-login-chart />
	<StoreChart />
	<Ranking />
</template>

<script setup>
	import OperationalCount from "./operational-count.vue";
	import StoreCount from "./store-count.vue";
	import StoreChart from "./store-chart.vue";
	import Ranking from "./ranking.vue";
	import StWelcome from "./components/st-welcome.vue";
	import StLoginChart from "./components/st-loginChart.vue";
	import StMineadmin from "./components/st-mineadmin.vue";
	import StAnnounced from "./components/st-announced.vue";
	import { provide, ref, onMounted, watchEffect } from "vue";
	import dayjs from "dayjs";
	import { getDataNow } from "@/api/home/index.js";

	const homeTimeText = ref("今日");
	provide("homeTimeText", homeTimeText);

	const rangeValue = ref([
		dayjs(new Date()).format("YYYY-MM-DD"),
		dayjs(new Date()).format("YYYY-MM-DD"),
	]);
	provide("rangeValue", rangeValue);

	const totlaCount = ref({});

	onMounted(() => {
		getData();
	});

	const getData = () => {
		let startTime = rangeValue.value[0] + " 00:00";
		let endTime = rangeValue.value[1] + " 23:59";
		getDataNow({ time: startTime + "," + endTime })
			.then((result) => {
				for (let key in result.data) {
					totlaCount.value[key] =
						Math.round(parseFloat(result.data[key]) * 1000) / 1000;
				}
				if(startTime == '2025-01-01 00:00'){
					totlaCount.value.daohuoyubao = (totlaCount.value.daohuoyubao + 423492.96).toFixed(2)
					totlaCount.value.tihuodan = (totlaCount.value.tihuodan + 423492.96).toFixed(2)
					totlaCount.value.shijitihuo = (totlaCount.value.shijitihuo + 423492.96).toFixed(2)
					totlaCount.value.zch_zl = (totlaCount.value.zch_zl + 15359.28).toFixed(2)
				}else{
					
				}
				
				console.log(totlaCount.value);
			})
			.catch((err) => {
				console.log(err);
			});
	};

	watchEffect(() => {
		getData();
	});
</script>

<style lang="less" scoped>
	.m-t-2 {
		margin-top: 20px;
	}
</style>
